home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc1_2_x / onlnrfpr.sit / Parse Functions / background_3763.txt < prev    next >
Text File  |  1991-06-18  |  11KB  |  407 lines

  1. -- background: 3763 from stack: in
  2. -- bmap block id: 4463
  3. -- flags: 0000
  4. -- background id: 0
  5. -- name: Protos
  6.  
  7.  
  8. -- part 1 (field)
  9. -- low flags: 04
  10. -- high flags: 0002
  11. -- rect: left=75 top=2 right=18 bottom=187
  12. -- title width / last selected line: 0
  13. -- icon id / first selected line: 0 / 0
  14. -- text alignment: 0
  15. -- font id: 3
  16. -- text size: 9
  17. -- style flags: 0
  18. -- line height: 12
  19. -- part name: FileName
  20.  
  21.  
  22. -- part 2 (field)
  23. -- low flags: 04
  24. -- high flags: 0002
  25. -- rect: left=250 top=2 right=18 bottom=411
  26. -- title width / last selected line: 0
  27. -- icon id / first selected line: 0 / 0
  28. -- text alignment: 0
  29. -- font id: 3
  30. -- text size: 9
  31. -- style flags: 0
  32. -- line height: 12
  33. -- part name: Returns
  34.  
  35.  
  36. -- part 3 (field)
  37. -- low flags: 04
  38. -- high flags: 0007
  39. -- rect: left=75 top=21 right=73 bottom=411
  40. -- title width / last selected line: 0
  41. -- icon id / first selected line: 0 / 0
  42. -- text alignment: 0
  43. -- font id: 3
  44. -- text size: 9
  45. -- style flags: 0
  46. -- line height: 12
  47. -- part name: Prototype
  48.  
  49.  
  50. -- part 4 (button)
  51. -- low flags: 00
  52. -- high flags: 2000
  53. -- rect: left=382 top=217 right=240 bottom=416
  54. -- title width / last selected line: 0
  55. -- icon id / first selected line: 1013 / 1013
  56. -- text alignment: 1
  57. -- font id: 0
  58. -- text size: 12
  59. -- style flags: 0
  60. -- line height: 16
  61. -- part name: Next
  62. ----- HyperTalk script -----
  63. on mouseUp
  64.   go to next card
  65. end mouseUp
  66.  
  67.  
  68. -- part 5 (button)
  69. -- low flags: 00
  70. -- high flags: 2000
  71. -- rect: left=0 top=216 right=240 bottom=25
  72. -- title width / last selected line: 0
  73. -- icon id / first selected line: 1014 / 1014
  74. -- text alignment: 1
  75. -- font id: 0
  76. -- text size: 12
  77. -- style flags: 0
  78. -- line height: 16
  79. -- part name: Prev
  80. ----- HyperTalk script -----
  81. on mouseUp
  82.   go to previous card
  83. end mouseUp
  84.  
  85.  
  86. -- part 6 (button)
  87. -- low flags: 00
  88. -- high flags: A004
  89. -- rect: left=34 top=218 right=237 bottom=193
  90. -- title width / last selected line: 0
  91. -- icon id / first selected line: 0 / 0
  92. -- text alignment: 1
  93. -- font id: 0
  94. -- text size: 12
  95. -- style flags: 0
  96. -- line height: 16
  97. -- part name: Read Header Files
  98. ----- HyperTalk script -----
  99. on mouseUp
  100.   put false into multi
  101.   put 0 into fileNumber
  102.  
  103.   answer "Shall I go straight on and export the data after IΓÇÖve read it in?" with "Yes", "No"
  104.   if it is "Yes" then
  105.     put true into batchMode
  106.   else
  107.     put false into batchMode
  108.   end if
  109.  
  110.   answer "Parse one file or the list from a folder?" with "Cancel", "Many", "One"
  111.  
  112.   if it is "Cancel" then exit mouseUp
  113.  
  114.   if it is "One" then
  115.     answer file "C header file to parse:" of type "TEXT"
  116.     if it is empty then exit mouseUp
  117.     put it into fileName
  118.     -- this function is in home and strips off the path
  119.     put lastHCItem(":", fileName) into shortFileName
  120.     put getPath(fileName) into path
  121.  
  122.   end if
  123.  
  124.   if it is "Many" then
  125.     put true into multi
  126.     put 1 into fileNumber
  127.     answer file "Open any file in the source folder:" of type "TEXT"
  128.     if it is empty then exit mouseUp
  129.     put it into fileName
  130.     -- this gets the path from the pull file and path
  131.     put getPath(fileName) into path
  132.     put files(path) into background fld "Files"
  133.     put background fld "files" into fileList
  134.  
  135.   end if
  136.  
  137.   repeat
  138.  
  139.     if multi then
  140.       -- get the next file name from the list
  141.       put line fileNumber of fileList into fileName
  142.  
  143.       if fileName is empty then
  144.         if batchMode then
  145.           doExport "New TextBase"
  146.         end if
  147.         beep
  148.         beep
  149.         beep
  150.         exit mouseUp
  151.       end if
  152.  
  153.       put fileName into shortFileName
  154.       put path before fileName
  155.       put fileNumber + 1 into fileNumber
  156.     end if
  157.  
  158.     open file fileName
  159.     put "Reading file number: " & fileNumber -1 & " ΓÇ£" &fileName & "ΓÇ¥ΓǪ"
  160.     read from file fileName until return
  161.  
  162.     go to the last card of background "Protos"
  163.  
  164.     repeat while it is not empty
  165.       put it into line
  166.       set cursor to busy
  167.  
  168.       if isCfunction(line) then
  169.         -- collect the function
  170.         put offset(")", line) into closeBracketAt
  171.         -- test for multi-line functions
  172.         if closeBracketAt is 0 then
  173.           read from file fileName until ")"
  174.           put line & it & ";" into funcLine
  175.         else
  176.           -- handle single line function prototypes
  177.           put character 1 to closeBracketAt of line & ";" into funcLine
  178.         end if
  179.  
  180.         -- replaces tabs with spaces
  181.         put stripTabs(funcLine) into funcLine
  182.  
  183.         -- remove the return types
  184.         put offset("(", funcLine) into openBracketAt
  185.         if openBracketAt is not zero then
  186.  
  187.           -- scan back over spaces to find the function name
  188.           repeat with i = openBracketAt down to 1
  189.             if character i of funcLine is not space then exit repeat
  190.           end repeat
  191.  
  192.           -- scan back until we find the space before the function name
  193.           repeat with i = i - 3 down to 1
  194.             if character i of funcLine is space then exit repeat
  195.           end repeat
  196.  
  197.           put character 1 to i of funcLine into returnType
  198.           delete character 1 to i of funcLine
  199.         end if
  200.  
  201.         -- now prepare to put the information in a card
  202.         doMenu "New Card"
  203.         put shortFileName into background field "FileName"
  204.  
  205.         if word 1 of returnType is "pascal" then
  206.           delete word 1 of returnType
  207.         end if
  208.         if word 1 of returnType is empty then
  209.           put "void" into returnType
  210.         end if
  211.  
  212.         put returnType into background field "Returns"
  213.  
  214.         -- strip off leading spaces
  215.         repeat with i = 1 to the number of chars in funcLine
  216.           if character 1 of funcLine is space or character 1 of funcLine is tab then
  217.             delete character 1 of funcLine
  218.           else
  219.             exit repeat
  220.           end if
  221.         end repeat
  222.  
  223.         -- this gets rid of the carriage returns in the text
  224.         repeat with i = 1 to the number of words in funcLine
  225.           put word i of funcLine & space after background field "ProtoType"
  226.         end repeat
  227.  
  228.       end if
  229.       read from file fileName until return
  230.     end repeat -- no more lines to read
  231.     if not multi then
  232.       close file fileName
  233.       hide msg
  234.       exit mouseUp
  235.     end if
  236.     close file fileName
  237.   end repeat -- reading multi files
  238. end mouseUp
  239.  
  240. -- This should be improved but works well enough for the MPW headers
  241. function isCfunction line
  242. if word 1 of line is "pascal" then
  243.   return true
  244. else
  245.   return false
  246. end if
  247. end isCfunction
  248.  
  249. -- replaces tabs with spaces
  250. function stripTabs line
  251. repeat with i = 1 to the number of characters in line
  252.   if character i of line is tab then
  253.     put space into character i of line
  254.   end if
  255. end repeat
  256. return line
  257. end stripTabs
  258.  
  259. -- pinched from Home for completeness
  260. function lastHCItem delim,theText
  261. -- returns the portion of <theText> that follows the last <delim>
  262. if delim is in theText then
  263.   put lastHCItem(delim,char offset(delim,theText) + 1 to length(theText) of theText) into theText
  264. end if
  265. return theText
  266. end lastHCItem
  267.  
  268. function getPath theText
  269. -- returns the portion of <theText> up to the last <delim>
  270. repeat with i = the number of chars in theText down to 1
  271.   if character i of theText is ":" then exit repeat
  272. end repeat
  273. return character 1 to i of theText
  274. end getPath
  275.  
  276. -- This sorts the cards by the function name
  277. -- outputs the text to a file with the words wrapped at the
  278. -- first word break after 65 characters are counted
  279. -- output is: functionName(parameters); // type  fileName.h
  280. -- By: Peter Marks Access Informatics (02) 555 8414
  281.  
  282. on doExport fileName
  283.   sort by field "ProtoType"
  284.   put "Sorting the stack, please waitΓǪ" into msg
  285.  
  286.   open file fileName
  287.   write "=" to file fileName
  288.   repeat with i = 1 to the number of cards in this stack
  289.     go to card i
  290.     set cursor to busy
  291.     put background fld "Prototype" & " // " & background fld "returns" & " <" & background fld "fileName" & ">|" into outLine
  292.  
  293.     -- write out the text, wrapping at the first word after 61 chars wide
  294.     put false into break
  295.     repeat with j = 1 to the number of characters in outline
  296.       if break and character j of outline is space then
  297.         write return to file fileName
  298.         put false into break
  299.       end if
  300.       write character j of outline to file fileName
  301.       if j mod 61 is zero then
  302.         put true into break -- break when you can!
  303.         set cursor to busy
  304.       end if
  305.     end repeat
  306.     write return to file fileName
  307.  
  308.   end repeat
  309.   write "=" to file fileName
  310.   close file fileName
  311.   beep
  312. end doExport
  313.  
  314.  
  315. -- part 7 (field)
  316. -- low flags: 05
  317. -- high flags: 0007
  318. -- rect: left=85 top=139 right=203 bottom=217
  319. -- title width / last selected line: 0
  320. -- icon id / first selected line: 0 / 0
  321. -- text alignment: 0
  322. -- font id: 3
  323. -- text size: 9
  324. -- style flags: 0
  325. -- line height: 12
  326. -- part name: Files
  327.  
  328.  
  329. -- part 8 (button)
  330. -- low flags: 00
  331. -- high flags: A004
  332. -- rect: left=2 top=180 right=202 bottom=82
  333. -- title width / last selected line: 0
  334. -- icon id / first selected line: 0 / 0
  335. -- text alignment: 1
  336. -- font id: 3
  337. -- text size: 9
  338. -- style flags: 0
  339. -- line height: 12
  340. -- part name: Delete Cards
  341. ----- HyperTalk script -----
  342. on mouseUp
  343.   answer "Do you want to delete all data from this stack?" with "Yes", "Cancel"
  344.   if it is "Cancel" then exit mouseUp
  345.  
  346.   repeat with i = 2 to the number of cards in this stack
  347.     go to card 2
  348.     doMenu "Delete Card"
  349.     set cursor to busy
  350.   end repeat
  351. end mouseUp
  352.  
  353.  
  354. -- part 9 (button)
  355. -- low flags: 00
  356. -- high flags: A004
  357. -- rect: left=199 top=218 right=237 bottom=379
  358. -- title width / last selected line: 0
  359. -- icon id / first selected line: 0 / 0
  360. -- text alignment: 1
  361. -- font id: 0
  362. -- text size: 12
  363. -- style flags: 0
  364. -- line height: 16
  365. -- part name: Export To OnBase
  366. ----- HyperTalk script -----
  367. -- This sorts the cards by the function name
  368. -- outputs the text to a file with the words wrapped at the
  369. -- first word break after 65 characters are counted
  370. -- output is: functionName(parameters); // type  fileName.h
  371. -- By: Peter Marks Access Informatics (02) 555 8414
  372.  
  373. on mouseUp
  374.   ask file "Name your export file:" with "TextBase"
  375.   if it is empty then exit mouseUp
  376.   put it into fileName
  377.   sort by field "ProtoType"
  378.   put "Sorting the stack, please waitΓǪ" into msg
  379.  
  380.   open file fileName
  381.   write "=" to file fileName
  382.   repeat with i = 2 to the number of cards in this stack
  383.     go to card i
  384.     set cursor to busy
  385.     put background fld "Prototype" & " // " & background fld "returns" & " <" & background fld "fileName" & ">|" into outLine
  386.  
  387.     -- write out the text, wrapping at the first word after 61 chars wide
  388.     put false into break
  389.     repeat with j = 1 to the number of characters in outline
  390.       if break and character j of outline is space then
  391.         write return to file fileName
  392.         put false into break
  393.       end if
  394.       write character j of outline to file fileName
  395.       if j mod 61 is zero then
  396.         put true into break -- break when you can!
  397.         set cursor to busy
  398.       end if
  399.     end repeat
  400.     write return to file fileName
  401.  
  402.   end repeat
  403.   write "=" to file fileName
  404.   close file fileName
  405.   beep
  406. end mouseUp
  407.